Programming Voice Interfaces by Walter Quesada and Bob Lautenbach

Programming Voice Interfaces by Walter Quesada and Bob Lautenbach

Author:Walter Quesada and Bob Lautenbach
Language: eng
Format: mobi, epub
Publisher: O'Reilly Media, Inc.
Published: 2017-10-11T04:00:00+00:00


def alexa_speech_recognizer(audio_stream): url = 'https://access-alexa-na.amazon.com/v1/avs/speechrecognizer/recognize' boundary = 'this-is-a-boundary' headers = { 'Authorization': 'Bearer %s' % token, 'Content-Type': 'multipart/form-data; boundary=%s' % boundary, 'Transfer-Encoding': 'chunked', } data = alexa_speech_recognizer_generate_data(audio_stream, boundary) resp = requests.post(url, headers=headers, data=data) platform.indicate_processing(False) process_response(resp)

Here we see a request being prepared for the AVS recognize endpoint. The headers suggest it’s a multipart chunked message with the Authorization header set to our refreshed OAuth token. Before the call is made to the endpoint, however, the audio_stream is converted to the chunked data in the alexa_speech_recognizer_generate_data function. Once the data is ready, it’s set to the data parameter, along with URL and headers in the requests.post function. Once that returns and populates resp with the AVS response, the platform.indicate_processing(False) call will turn off the processing LED and then the process_response(resp) call will prepare the response for audio playback on your device.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.